<template>
  <div>
    <h2>一日用电量变化图</h2>
    <div class="chart3" id="myEchartsFive">
        图表内容
    </div>
  </div>
</template>

<script>
import {inject,onMounted,reactive} from "vue"
export default {
  setup(){
    let $echarts=inject("echarts")
    let $http=inject("axios")
    let data=reactive({})
    async function getState(){
        data=await $http({url:"/four/data"})
      }
    onMounted(()=>{
      getState().then(()=>{
        console.log("折线图",data)
        let myChart=$echarts.init(document.getElementById("myEchartsFive"))
        myChart.setOption({
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross'
    }
  },
  xAxis: {
    type: 'category',
    boundaryGap: true,
    // prettier-ignore
    axisLine:{
      lineStyle:{
        color:"#fff"
      }
    },
    data: ['00:00', '01:15', '02:30', '03:45', '05:00', '06:15', '07:30', '08:45', '10:00', '11:15', '12:30', '13:45', '15:00', '16:15', '17:30', '18:45', '20:00', '21:15', '22:30', '23:45']
  },
  yAxis: {
    
    type: 'value',
    axisLabel: {
      formatter: '{value} W',
      color:"#fff",
      margin: 0,
    },
    axisPointer: {
      snap: true
    }
  },
  visualMap: {
    show: false,
    dimension: 0,
    pieces: [
      {
        lte: 6,
        color: 'green'
      },
      {
        gt: 6,
        lte: 8,
        color: 'red'
      },
      {
        gt: 8,
        lte: 14,
        color: 'green'
      },
      {
        gt: 14,
        lte: 17,
        color: 'red'
      },
      {
        gt: 17,
        color: 'green'
      }
    ]
  },
  series: [
    {
      name: '电量',
      type: 'line',
      smooth: true,
      // prettier-ignore
      data: [300, 280, 250, 260, 270, 300, 550, 500, 400, 390, 380, 390, 400, 500, 600, 750, 800, 700, 600, 400],
      markArea: {
        itemStyle: {
          color: 'rgba(255, 173, 177, 0.4)'
        },
        data: [
          [
            {
              name: '早高峰',
              xAxis: '07:30'
            },
            {
              xAxis: '10:00'
            }
          ],
          [
            {
              name: '晚高峰',
              xAxis: '17:30'
            },
            {
              xAxis: '21:15'
            }
          ]
        ]
      }
    }
  ]
})
      })
    })
    return {
      getState,data
    }
  }
}
</script>

<style>
.chart3{
height: 3.6rem;
left: 0.1875rem;
}
h2{
height: 0.2rem;
color: #0b5ae2;
line-height: 0.25rem;
text-align: center;
font-size: 0.2rem;
margin-bottom: 0;
}
</style>